#e
#Title[zNȕv]
#Text[gE}̈B]
#ScriptVersion[2]

script_enemy_main
{
	let scroll=0;
	let flag=0;
	let flag2=0;
	let cx=GetCenterX();
	let cy=GetCenterY();
	let boss=GetCurrentScriptDirectory~"img\boss7-2.png";
	let eye=GetCurrentScriptDirectory~"img\bg7-1.png";
	let asa=GetCurrentScriptDirectory~"img\bg7-2.png";
	LoadUserShotData(GetCurrentScriptDirectory~"shot.txt");
	@Initialize
	{
		SetLife(600);
		SetDamageRate(10,0);
		SetInvincibility(240);
		LoadGraphic(boss);
		LoadGraphic(eye);
		LoadGraphic(asa);
		shottask;
		movetask;
		drawtask;
		SetEnemyMarker(false);
		MagicCircle(false);
		SetDurableSpellCard;
	}
	@MainLoop
	{
		yield;
	}
	@Finalize
	{
		DeleteGraphic(boss);
		DeleteGraphic(eye);
		DeleteGraphic(asa);
	}
	@DrawLoop
	{
		SetTexture(boss);	
		if(flag==1)
		{
			SetGraphicRect(52,0,81,63);
		}
		else if(flag==2)
		{
			SetGraphicRect(24,0,52,63);
		}
		else
		{
			SetGraphicRect(0,0,24,63);
		}
		if(flag==3)
		{
			SetAlpha(0);
		}
		else
		{
			SetAlpha(255);
		}
		SetGraphicScale(1,1);
		SetGraphicAngle(0,0,0);
		DrawGraphic(GetX,GetY);
	}
	@BackGround
	{
		SetColor(128,128,128);
		SetTexture(eye);	
		SetGraphicRect(0,0,384,448);
		SetAlpha(255);
		SetGraphicScale(1,1);
		SetGraphicAngle(0,0,0);
		DrawGraphic(cx,cy);
		SetColor(255,255,255);
		SetTexture(asa);	
		SetGraphicRect(0,0,888,189*5);
		SetAlpha(64);
		SetGraphicScale(0.5,0.75);
		SetGraphicAngle(0,0,0);
		DrawGraphic(cx+scroll,cy);
		DrawGraphic(cx+scroll-444,cy);
		if(scroll>444)
		{
			scroll=0;
		}
	}
	task shottask
	{
		wait(240);
		CreateObjLaser(45);
		CreateObjLaser(135);
	}
	task movetask
	{
		wait(120);
		SetScore(30000);
		SetMovePosition02(cx,GetClipMinY-120,60);
		SetTimer(80);
		PlaySE(GetCurrentScriptDirectory~"seUseSpellCard.wav");
		CutIn(YOUMU,"zNȕv",0,0,0,0,0);
		wait(60);
		SetAngle(90);
		wait(60);
		let speed=0.75;
		let angle=GetAngle;
		SetMovePosition02(GetX,GetClipMinY+64,120);
		wait(120);
		SetSpeed(0.5);
		angle=GetAngle;
		loop(90)
		{
			angle++;
			SetAngle(angle);
			yield;
		}
		SetMovePosition02(GetClipMinX+64,GetY,60);
		wait(60);
		SetSpeed(0.5);
		angle=GetAngle;
		loop(90)
		{
			angle--;
			SetAngle(angle);
			yield;
		}
		SetMovePosition02(GetX,GetClipMaxY-64,120);
		wait(120);
		SetSpeed(0.5);
		angle=GetAngle;
		loop(90)
		{
			angle--;
			SetAngle(angle);
			yield;
		}
		SetMovePosition02(GetClipMaxX-64,GetY,120);
		wait(120);
		SetSpeed(0.5);
		angle=GetAngle;
		loop(90)
		{
			angle--;
			SetAngle(angle);
			yield;
		}
		SetMovePosition02(GetX,GetClipMinY+64,120);
		wait(120);
		SetSpeed(0.5);
		angle=GetAngle;
		loop(90)
		{
			angle--;
			SetAngle(angle);
			yield;
		}
		SetMovePosition02(cx,GetClipMinY+64,60);
		wait(60);
		SetSpeed(0.5);
		angle=GetAngle;
		loop(90)
		{
			angle--;
			SetAngle(angle);
			yield;
		}
		SetMovePosition02(cx,GetClipMaxY+120,180);
		wait(180);
		flag2=1;
		SetAngle(270);
		DeleteEnemyShot(SHOT);
		wait(120);

		loop(2)
		{
			SetMovePosition02(GetPlayerX,GetClipMaxY+120,0);	
			yield;
			SetMovePosition02(GetPlayerX,GetClipMinY-120,180);
			wait(180);

			SetMovePosition02(GetPlayerX,GetClipMinY-120,0);	
			yield;
			SetMovePosition02(GetPlayerX,GetClipMaxY+120,180);
			wait(180);
		}
		SetMovePosition02(GetClipMinX-120,GetPlayerY,0);	
		yield;
		SetMovePosition02(GetClipMaxX+120,GetPlayerY,180);
		wait(180);
		SetMovePosition02(GetClipMaxX+120,GetPlayerY,0);	
		yield;
		SetMovePosition02(GetClipMinX-120,GetPlayerY,180);
		wait(180);
		SetMovePosition02(GetPlayerX,GetClipMaxY+120,0);	
		yield;
		SetMovePosition02(GetPlayerX,GetClipMinY-120,180);
		wait(180);
		SetMovePosition02(GetPlayerX,GetClipMinY-120,0);	
		yield;
		SetMovePosition02(GetPlayerX,GetClipMaxY+120,180);
		wait(180);
		flag2=2;
		SetAngle(270);
		DeleteEnemyShot(SHOT);
		wait(120);
		loop
		{
			SetSpeed(speed);
			SetAngle(GetAngleToPlayer);
			speed+=0.0005;
			yield;
		}
	}
	task drawtask
	{
		let x=0;
		loop
		{	
			if(GetX>x+0.5)
			{
				flag=1;
			}
			else if(GetX<x-0.5)
			{
				flag=2;
			}
			else
			{
				flag=0;
			}
			if(GetTimer<79)
			{
				flag=3;
			}
			x=GetX;
			scroll++;
			yield;
		}
	}
	task CreateObjLaser(let angle)
	{
		let count=0;
		let r=0;
		let obj = Obj_Create(OBJ_LASER);
		Obj_SetPosition(obj,GetX+64*1.4241356*cos(GetAngle+angle),GetY+64*1.4241356*sin(GetAngle+angle));
		Obj_SetAngle(obj, GetAngle+270);
		ObjShot_SetGraphic(obj, 254);
		ObjShot_SetDelay(obj,0);
		ObjLaser_SetLength(obj, 128);
		ObjLaser_SetWidth(obj, 64);
		Obj_SetAutoDelete(obj,false);
		ObjLaser_SetSource(obj,false);
		while(!Obj_BeDeleted(obj))
		{
			r=rand(0,128);
			Obj_SetPosition(obj,GetX+64*1.4241356*cos(GetAngle+angle),GetY+64*1.4241356*sin(GetAngle+angle));
			Obj_SetAngle(obj, GetAngle+270);
			if(flag2==0)
			{
				CreateShot01(Obj_GetX(obj)+r*cos(Obj_GetAngle(obj)),Obj_GetY(obj)+r*sin(Obj_GetAngle(obj)),rand(0.1,1),Obj_GetAngle(obj)-90,177,0);
			}
			if(flag2==1&&count%5==0)
			{
				CreateShot01(Obj_GetX(obj)+r*cos(Obj_GetAngle(obj)),Obj_GetY(obj)+r*sin(Obj_GetAngle(obj)),rand(0.5,2),Obj_GetAngle(obj)-90,177,0);
			}
			if(flag2==2&&count%5==0)
			{
				CreateShot01(Obj_GetX(obj)+r*cos(Obj_GetAngle(obj)),Obj_GetY(obj)+r*sin(Obj_GetAngle(obj)),rand(0.2,2),Obj_GetAngle(obj)-90,177,0);
			}
			count++;
			yield;
		}
	}
	function wait(w) 
	{
		loop(w)
		{
			yield;
		}
	}
}